<?php

class Danhmuc_CategoryController extends Zend_Controller_Action {

	public function init() {
		$this->params = $this->getRequest()->getParams();
		System_Template::using("blank", "Admin");
		$this->model = new Danhmuc_Model_Category();
		parent::init();
	}

	public function indexAction() {
		$this->view->maintitle = "Danh sách loại tour";
		$model = new Danhmuc_Model_Category();
		$name = $this->_request->getParam("name");
		$phamvi = $this->_request->getParam("phamvi");
		$this->view->name = $name;
		$this->view->phamvi = $phamvi;
		$this->view->website = $website;
		$parameter = array('name' => $name, 'website' => $website,
				'phamvi' => $phamvi);
		$count = $model->count($parameter);
		$paging = common::pagingAuto($count);
		$data = $model->SelectAll($parameter, $paging[0], $paging[1]);
		$this->view->data = $data;
		common::showButton('delete');
		common::showButton('add');
	}
	public function inputAction() {
		common::showButton('save');
		common::showButton('back');
		$this->qldst = new Danhmuc_Model_Category();
		$id = $this->params['id'];
		$this->view->flag = 0;
		if ($id == 0) {
			$this->view->maintitle = "Thêm thông tin tour";
		} else {
			$this->view->maintitle = "Cập nhật thông tin tour";
			$data = $this->qldst->FindById($id);
			$this->view->data = $data;
			$this->view->id = $id;
			$this->view->flag = 1;
		}
	}
	public function saveAction() {
		$r=$this->model->CheckExitsName($this->params['name']);
		if($r==1){
			$this->_redirect('/danhmuc/category/input');
		}else{
			$this->model->AddNewCatagory($this->params);
			$this->_redirect('/danhmuc/category/index');
		}
	}
	public function deleteAction() {
			$params = $this->getRequest()->getParams();
			$db = Zend_Db_Table::getDefaultAdapter();
			$ids = $params["DEL"];
			foreach($ids as $t){
				$db->delete("tour_category","id=".(int)$t);
			}
			$this->_redirect("/danhmuc/category/index");
	}
}

